import React from 'react';
import MyPatient from './myPatient';
import MyPatientEdit from './myPatientEdit';
export default class Index extends React.Component {
    constructor(props) {
        super(props);
        this.state = {
            showForm: false,
            refresh: Math.random(),
            isNew: false
        };
    }


    hideEditor() {
        this.setState({showForm: false, refresh: Math.random()});
    }

    showPE(args) {
        if (typeof args.isNew !== "undefined" && args.isNew) {
            this.setState({showForm: true, isNew: true});
        } else {
            this.setState({showForm: true, isNew: false, dataEdit: args});
        }
    }

    remove(targetKey) {
        if (targetKey === 'main') {
            return;
        }
        let activeKey = this.state.activeKey;
        let lastIndex;
        this.state.panes.forEach((pane, i) => {
            if (pane.key === targetKey) {
                lastIndex = i - 1;
            }
        });
        const panes = this.state.panes.filter(pane => pane.key !== targetKey);
        if (lastIndex >= 0 && activeKey === targetKey) {
            activeKey = panes[lastIndex].key;
        }
        this.setState({
            panes,
            activeKey
        });
    }

    render() {
        return (<div>
            <MyPatient showPE={this.showPE.bind(this)} refresh={this.state.refresh}/>
            <MyPatientEdit
                show={this.state.showForm}
                relative="main"
                title="编辑患者信息"
                hideEditor={this.hideEditor.bind(this)}
                dataEdit={this.state.dataEdit}
                isNew={this.state.isNew}
            />
        </div>);
    }
}
